import { CopyControllerBase } from "./CopyControllerBase";
import { ECopyType } from "../../../../../Message/Public/ECopyType";
import { MessageBlock } from "../../../../../Framework/MQ/MessageBlock";
import { SEightyCopyInfo } from "../../../../../Message/Public/SEightyCopyInfo";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { TCopy } from "../../../../../Message/Db/Tables/TCopy";
import { NetDispatcher } from "../../../../mvc/core/NetDispatcher";
import { EPublicCommand } from "../../../../../Message/Command/EPublicCommand";
import { EightyCopyView } from "../eightyCopy/EightyCopyView";
//class EightyCopyController
    
    export  class EightyCopyController extends CopyControllerBase
    {
        constructor()
        {
            super();
            return;
        }

        /* internal  */enterCopyHandler(): void
        {
            if (cache.copy.isInCopyType(ECopyType._ECopyEighty) && !cache.copy.isInKingCopy()) 
            {
                this.eightyCopyView.showInfoPanel();
                this.eightyCopyView.infoPanel.title = copy.name;
                this.eightyCopyView.updateInfoPanel(this._eightyInfo);
            }
            return;
        }

        /* internal  */onReceiveEightyCopyInfo(arg1: MessageBlock): void
        {
            this._eightyInfo = arg1.messageBase as SEightyCopyInfo;
            if (cache.copy.isInCopyType(ECopyType._ECopyEighty) && this._eightyInfo) 
            {
                this.eightyCopyView.updateInfoPanel(this._eightyInfo);
                if (this._eightyInfo.remainTime == -1) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_ClickCopyExit, null));
                }
            }
            return;
        }

        public /* override */ enterCopy(arg1: TCopy): void
        {
            super.enterCopy(arg1);
            this.enterCopyHandler();
            return;
        }

        public /* override */ leaveCopy(): void
        {
            super.leaveCopy();
            if (!cache.copy.isInKingCopy()) 
            {
                this.eightyCopyView.hideInfoPanel();
            }
            return;
        }

        protected /* override */ initServer(): void
        {
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicEightyCopyInfo, this.onReceiveEightyCopyInfo);
            return;
        }

        public get eightyCopyView(): EightyCopyView
        {
            if (!this._eightyCopyView) 
            {
                this._eightyCopyView = new EightyCopyView();
            }
            return this._eightyCopyView;
        }

        /* internal */ /* var */_eightyCopyView: EightyCopyView;

        /* internal */ /* var */_eightyInfo: SEightyCopyInfo;
    }
